OLE Object in RichText Field

Hey everyone,

I'm having a problem with part of my DXL code. Basically, what is happening is that I want a window to popup, in order to notify the user that they need to change/modify an object. I have a RichText field that shows an OLE object (used as a preview), and a text field used to keep track of what they want to input (their modification to the object). I'm using a block statement that will block the DXL from running again till the user submits a choice. It works fine on the first instance of this, but when the program loops through my module and finds another instance, the window pops up, but the same OLE object shows up again. I've put a few print statements into the code to see if it is actually another object, and I have confirmed that the object is changing. Here is part of my test code.

If anyone has any insight on this problem that would be awesome. Thanks!
 

void createCaption(DB box){
    string whatisthis = get(captionfield)
        print whatisthis
        Object newo = create below createcapobj
                
        newo."Paragraph Style" =  "<Object Text:Caption-Figure>"
        
        Buffer cap = create
 
        Object par = parent createcapobj
        while(par."Object Heading" "" ==""){
                par = parent par
        }
        string parnum = number par
        cap += "Figure " parnum "-" createcaprank "-" whatisthis
        newo."Object Text" = cap
        //release captionGUI
        hide captionGUI
}
 
int createCapGUI(Object o){
        string temp = createcapobj."Absolute Number"
 
        captionframe = richText(captionGUI,"Create Caption","",600,300,true)
        captionfield = field(captionGUI,"Caption Comment:","",50)
        captionfield->"top"->"spaced"->captionframe
        string s = richTextWithOle createcapobj."Object Text"
        set(captionframe,s)
        ok(captionGUI,"Create Caption",createCaption)
        //show captionGUI
        block captionGUI
        return 1
}

wcheng - Fri Feb 12 19:16:22 EST 2010

Re: OLE Object in RichText Field
Mathias Mamsch - Sat Feb 13 17:00:59 EST 2010

I am not sure, but I see the "Object o" parameter in the createCapGUI function is useless, since you always use the createcapobj in your functions. You did not post how you call the createCapGUI function, but if you do it like that:
 

for obj in current Module do {
        if ( is_this_a_figure_check(obj) && does_it_need_a_caption_check(obj) ) {
              createCapGUI obj
        }
    }

 


this would explain the behavior. But there is a bigger problem that is probably causing the behavior:

You forgot to destroy and recreate the captionGUI dialog box in the next call. If you inline your functions, then your code would probably look like this:

 

 

 

DB captionGUI = create "Create a caption dialog" 
 
for obj in module do {
 
       if (some checks) {
            createcapobj = obj
 
            // for the first call these functions will really create the dialog elements
            // the second and following calls will overwrite the captionframe and captionfield
            // variables. 
            captionframe = richText(captionGUI,"Create Caption","",600,300,true)
            captionfield = field(captionGUI,"Caption Comment:","",50)
            ... 
            // on the first call this will set the right captionframe. On the second call 
            // captionframe will point to an invisible field that has not been added to the dialog
            // box, since it was already realized at the time of its creation. 
            set(captionframe,s)
            ...
            // this will realize the dialog box in the first iteration, meaning you cannot
            // create any more elements in the dialog box after this call
            block captionGUI
            ...
            // this will just hide the dialog box, but if you call block again you will just show it again.
            hide captionGUI
       }
}



You probably need to move the DB captionGUI = create ... call into the loop and explicitly destroy it afterwards (if you use block) OR you need to move the creation of the dialog elements outside the loop and just set their content in the loop. You can create the elements of a dialog box only before it is realized, afterwards you will not get an error, but the elements will not be added to the dialog. I hope I am making sense here :-)

Regards, Mathias